Skip to content

Conversation

@codesrobertson
Copy link

Apologies that this is late--meant to submit around 6:30, and I just remembered I forgot to do the PR step.

@codesrobertson codesrobertson changed the title Submitting Hashmap exercises. Alex - Time Mar 31, 2020
Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, you hit most of all the learning goals here. Well done.

Take a look at my comments and let me know if you have any questions.

crossroads = []

list1.each do |n|
crossroads << n if list2.include?(n) != false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.include is an O(n) operation and you have this in a loop...

# Time Complexity: O(n)
# Space Complexity: O(n)

def intersection(list1, list2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but it's O(n * m) in time complexity. Using a hash you can get this to O(n + m) time complexity which is much better.

I encourage you to think about how to do this.

def palindrome_permutation?(string)
raise NotImplementedError, "palindrome_permutation? not implemented"
end
while string.empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while?

Suggested change
while string.empty?
if string.empty?

Comment on lines +1 to 4
# Time Complexity: O(n)
# Space Complexity: O(n)

def palindrome_permutation?(string)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +9 to +11
perm = string1.chars
mutant = string2.chars
mindflayer = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like DND too, but these aren't the best variable names.

Comment on lines +1 to 4
# Time Complexity: O(n)
# Space Complexity: O(n)

def permutations?(string1, string2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works only if the count of each letter is the same. It returns true however for heelo and hello.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants